package hongcheng.code_generator.database;

import hongcheng.code_generator.entity.config.CodeGeneratorConfig;
import hongcheng.code_generator.enumeration.DbNameEnum;
import hongcheng.code_generator.exception.CustomException;

/**
 * 	数据库元数据读取类工厂
 * */
public class DBMetadataReaderFactory {

	public static AbstractDBMetadataReader getDBMetadataReader(CodeGeneratorConfig codeGeneratorConfig) {
		String dbName = codeGeneratorConfig.getDbConfig().getDbName();
		DbNameEnum dbNameEnum = DbNameEnum.getByLowerName(dbName);
		if(dbNameEnum == DbNameEnum.MYSQL) {
			return new DefaultMySqlDBMetadataReader(codeGeneratorConfig);
		}else if(dbNameEnum == DbNameEnum.ORACLE) {
			return new DefaultOracleBMetadataReader(codeGeneratorConfig);
		}else {
			throw new CustomException("配置文件中{}数据库在系统中找不到对应的AbstractDBMetadataReader实现类") ;
		}
	}
}
